<!--
 * @Author: your name
 * @Date: 2022-03-15 15:31:53
 * @LastEditTime: 2022-03-15 15:53:25
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\eval的使用220315.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>eval的使用</title>
</head>
<body>
  <script>
    //   eval() 函数会将传入的字符串当做 JavaScript 代码进行执行。
  var fangfang=eval(new String('2 + 2')) 
  console.log(fangfang,"fangfang") //String { "2 + 2" }
  var fangfangTest=new String('2 + 2')
  console.log(fangfangTest,"fangfangTest") //String { "2 + 2" }
  var geyao=eval('2 + 2') 
  console.log(geyao,"geyao") //4
  </script>
</body>
</html>